﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleData.Infrastructure.JavaScript
{
	/// <summary>
	/// 
	/// </summary>
	public struct Text
	{
		public static readonly Text Null = ( string )null;

		internal string value;


		public int Length
		{ get { return this.value.Length; } }

		public int IndexOf( string value )
		{
			return this.value.IndexOf( value );
		}

		public override int GetHashCode()
		{
			if ( this.value != null )
				return this.value.GetHashCode();
			else
				return 0;
		}

		public override bool Equals( object obj )
		{
			if ( obj is Text )
				return this.value == ( ( Text )obj ).value;
			else
				return false;
		}

		public override string ToString()
		{
			return this.value;
		}

		#region [ Cast Operators Overload ]

		public static implicit operator Text( Number x )
		{
			return new Text() { value = x.ToString() };
		}

		public static implicit operator Text( String x )
		{
			return new Text() { value = x };
		}

		#endregion

		#region [ Concat Operator Overload ]

		public static Text operator +( Text x, Text y )
		{
			return new Text() { value = String.Concat( x.ToString(), y.ToString() ) };
		}

		#endregion

		#region [ Logical Operators Overload ]

		public static bool operator true( Text x )
		{
			return !String.IsNullOrEmpty( x.value );
		}

		public static bool operator false( Text x )
		{
			return String.IsNullOrEmpty( x.value );
		}

		public static bool operator !( Text x )
		{
			return String.IsNullOrEmpty( x.value );
		}

		public static bool operator ==( Text x, Text y )
		{
			return x.value == y.value;
		}

		public static bool operator !=( Text x, Text y )
		{
			return x.value != y.value;
		}

		#endregion
	}

}
